package com.zzz.framework.util;


import cn.hutool.core.bean.copier.CopyOptions;

import java.util.List;

/**
 * 包装 spring BeanUtils
 */
public class MyBeanUtil {
    private static final CopyOptions ignoreNullValueOption = CopyOptions.create().setIgnoreNullValue(true);

    private MyBeanUtil() {
    }

    /**
     * 拷贝对象
     *
     * @param source
     * @param target
     */
    public static void copyBean(Object source, Object target) {
        cn.hutool.core.bean.BeanUtil.copyProperties(source, target, ignoreNullValueOption);
    }

    /**
     * 拷贝对象
     *
     * @param source
     * @param targetClass
     * @return
     */
    public static <T> T copyBean(Object source, Class<T> targetClass) {
        return cn.hutool.core.bean.BeanUtil.toBean(source, targetClass, ignoreNullValueOption);
    }

    /**
     * 拷贝对象列表
     *
     * @param sourceList  待拷贝列表
     * @param targetClass 目标类型
     * @return
     */
    public static <T> List<T> copyList(List<?> sourceList, Class<T> targetClass) {
        return cn.hutool.core.bean.BeanUtil.copyToList(sourceList, targetClass, ignoreNullValueOption);
    }
}